To read from and write to files, the appropriate stream should first be opened via the standard library function fopen(), whose prototype is:
FILE *fopen(char *filename, char *description);
The filename and description arguments specify the name of the file and how it will be used, such as "r" for reading a text stream and "w" for writing to a text stream. The return value is a pointer to a FILE type: a data structure defined in stdio.h identifying the characteristics of the I/O device specified.
The fprintf() and fscanf() functions are very similar to printf() and scanf() except that their first argument is a FILE pointer:
int fprintf(FILE *stream, char *format_string, ...);
int fscanf(FILE *stream, char *format_string, ...);